on *:load:{
  If (!$isdir(ShortHand)) { mkdir ShortHand }
  write shorthand/shorthand.txt
  write shorthand/changeto.txt
  ms send SlAva i loaded your shorthand script
  echo 9 -a *** Shorthand Script Loaded! Type /shorthand to access the menu ***
}

alias shorthand { dialog -m shorthand shorthand }
dialog shorthand {
  title "Short Hand Script"
  size -1 -1 142 155
  option dbu
  list 101, 8 11 59 135, size
  box "Short Hand", 100, 4 3 67 147
  box "Change to", 200, 74 6 67 32
  button "Add", 300, 88 42 37 12
  button "Delete", 301, 88 58 37 12
  button "Done", 302, 88 136 37 12, ok
  edit "", 201, 77 19 61 10, read
}


on *:dialog:shorthand:init:*:{
  filter -xfo shorthand/shorthand.txt shorthand 101 $crlf
}

on *:dialog:shorthand:sclick:*:{
  If ($did == 101) { did -ra shorthand 201 $read(shorthand/changeto.txt,$did(101).sel) }
  If ($did == 300) { 
    var %sh $input(Enter shorthand text:,oe,Shorthand Script)
    var %ct $input(Enter text to change to:,oe,Shorthand Script)
    If (%sh) && (%ct) {
      did -a shorthand 101 %sh
      write shorthand/shorthand.txt %sh
      write shorthand/changeto.txt %ct
    }
  }
  If ($did == 301) && ($did(101).sel) { 
    var %line $did(101).sel
    write -dl $+ %line shorthand/shorthand.txt
    write -dl $+ %line shorthand/changeto.txt
    did -d shorthand 101 %line
  }
}

on *:input:#:{ 
  If (/* !iswm $1-) {
    haltdef
    var %text $1-
    var %num = 1
    while (%num != $calc($0 + 1)) {
      If ($intext($gettok($1-, [ %num ] ,32))) { 
        var %tok = $gettok(%text,%num,32)
        var %intext = $intext($gettok($1-, [ %num ] ,32))
        var %readline $read(shorthand/changeto.txt, [ %intext ] )
        var %text [ $puttok(%text, [ %readline ] , [ %num ] ,32) ]
      }
      inc %num
    }
    msg $chan %text
  }
}


alias -l intext {
  var %readline 1
  While (%readline != $calc($lines(shorthand/shorthand.txt) + 1)) {
    If ($read(shorthand/shorthand.txt,%readline) == $1) { return %readline }
    inc %readline
  }
}
